using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarClaimExpInfoDB
    {
        public CarClaimExpInfoDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarClaimExpInfo carclaimexp)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarClaimExpInfoInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarClaimExpId", carclaimexp.ProviderCarClaimExpId);
            _sPara.Add("@ProviderCompanyId", carclaimexp.ProviderCompanyId);
            _sPara.Add("@Description", carclaimexp.Description);
            _sPara.Add("@ClaimCount", carclaimexp.ClaimCount);
            _sPara.Add("@FromClaimValue", carclaimexp.FromClaimAmount);
            _sPara.Add("@ToClaimValue", carclaimexp.ToClaimAmount);
            _sPara.Add("@ClaimRate", carclaimexp.ClaimRate);
            _sPara.Add("@RefCEUserId", carclaimexp.RefCEUserId);
            _sPara.Add("@Status", carclaimexp.Status);
            _sPara.Add("@Finfo1", carclaimexp.FInfo1);
            _sPara.Add("@Dinfo1", carclaimexp.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete(Int64 ProviderCarClaimExpId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarClaimExpInfoDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarClaimExpId", ProviderCarClaimExpId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

        public CarClaimExpInfoList GetProviderCarClaimExpInfoList(Int64 ProviderCompanyId)
        {
            CarClaimExpInfoList _claimlist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpInfoSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _claimlist = new CarClaimExpInfoList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarClaimExpInfo _claim = new CarClaimExpInfo();
                        _claim = FillDataRecord(_dt, i);
                        _claimlist.Add(_claim);
                    }
                }
            }
            return _claimlist;
        }


        public CarClaimExpInfo GetProviderCarClaimExpInfo(Int64 ProviderCompanyId, Int32 CXCoverTypeId)
        {
            CarClaimExpInfo _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpInfoSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCoverTypeId", CXCoverTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarClaimExpInfo();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public CarClaimExpInfo GetProviderCarClaimExpInfo(Int64 ProviderCarClaimExpInfoId)
        {
            CarClaimExpInfo _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpInfoSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarClaimExpInfoId", ProviderCarClaimExpInfoId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarClaimExpInfo();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public CarClaimExpInfo GetProviderCarClaimExpInfo(Int64 ProviderCompanyId, int ClaimCount, int FromClaimValue, int ToClaimValue)
        {
            CarClaimExpInfo _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpInfoSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ClaimCount", ClaimCount);
            _spara.Add("@FromClaimValue", FromClaimValue);
            _spara.Add("@ToClaimValue", ToClaimValue);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarClaimExpInfo();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public bool CheckProviderCarClaimExpInfoDuplicate(Int64 CurrentClaimInfoId, Int64 ProviderCompanyId, int ClaimCount, int FromClaimValue, int ToClaimValue)
        {
            bool _retValue = false;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpInfoDuplicateSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarClaimExpId", CurrentClaimInfoId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ClaimCount", ClaimCount);
            _spara.Add("@FromClaimValue", FromClaimValue);
            _spara.Add("@ToClaimValue", ToClaimValue);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _retValue = true;
                }
            }
            return _retValue;
        }


        private CarClaimExpInfo FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarClaimExpInfo myCarClaimExpInfo = new CarClaimExpInfo();
            myCarClaimExpInfo.ProviderCarClaimExpId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarClaimExpId"].ToString());
            myCarClaimExpInfo.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarClaimExpInfo.Description = myDataTable.Rows[RowId]["Description"].ToString();
            myCarClaimExpInfo.ClaimCount = Convert.ToInt32( myDataTable.Rows[RowId]["ClaimCount"].ToString());
            myCarClaimExpInfo.FromClaimAmount = Convert.ToInt32(myDataTable.Rows[RowId]["FromClaimValue"].ToString());
            myCarClaimExpInfo.ToClaimAmount = Convert.ToInt32(myDataTable.Rows[RowId]["ToClaimValue"].ToString());
            myCarClaimExpInfo.ClaimRate = Convert.ToSingle(myDataTable.Rows[RowId]["ClaimRate"].ToString());
            myCarClaimExpInfo.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarClaimExpInfo.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            
            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarClaimExpInfo.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarClaimExpInfo.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarClaimExpInfo.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCarClaimExpInfo;
        }
        
    }
}